package top.yiwyn.common;

import java.io.Serializable;

public class ResultBean<T> implements Serializable {
    public static final int SUCCCESS = 200;
    public static final int FAIL = 400;

    private int code;
    private String msg;
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


    public ResultBean(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ResultBean succ(T data) {
        return new ResultBean(SUCCCESS, "请求成功", data);
    }

    public static <T> ResultBean succ(String message, T data) {
        return new ResultBean(SUCCCESS, message, data);
    }


    public static ResultBean fail(Throwable e) {
        return new ResultBean(FAIL, e.getMessage(), null);
    }

    public static ResultBean fail(String message) {
        return new ResultBean(FAIL, message, null);
    }

}
